package ssm.ann.config.listener;

import lombok.extern.java.Log;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.ServletRequestHandledEvent;

/**
 * 专门监听 ServletRequestHandledEvent 事件的监听器
 */
@Log
@Component
public class ServletReqestHandledEventListener implements ApplicationListener<ServletRequestHandledEvent> {

    @Override
    public void onApplicationEvent(ServletRequestHandledEvent event) {
        //url=[/demowar_war/controller/hello]; client=[127.0.0.1]; method=[GET]; servlet=[dispatcher]; session=[null]; user=[null]; time=[143ms]; status=[OK]
        log.info(event.getDescription());
        log.info("返回状态码为：" + event.getStatusCode()); //返回状态码为：200
        log.info("异常信息为：" + event.getFailureCause()); //异常信息为：null
        log.info("处理请求耗时为：" + event.getProcessingTimeMillis()); //处理请求耗时为：143
        log.info("事件源为：" + event.getSource()); //事件源为：org.springframework.web.servlet.DispatcherServlet@3e7fadbb
    }
}
